package PROYECTO2.src.Naves.Enemigos;
import java.net.URL;
import java.util.Random;

import javax.swing.ImageIcon;

import PROYECTO2.src.Explosiones_Disparos.Shot;
import PROYECTO2.src.Naves.Spaceship;

public class HeavyRaider extends Cylon {

	protected static final URL url = (Spaceship.class.getClassLoader().getResource("PROYECTO2/src/img/Enemigo/HeavyRaider.gif"));
	protected static final URL urlUp = (Spaceship.class.getClassLoader().getResource("PROYECTO2/src/img/Enemigo/HeavyRaiderUP.gif"));

	private static final int defaultWidth = 40;
	private static final int defaultHeight = 32;
	private static final int defaultSpeed = 15;
	private static final int defaultLife = 3;
	private boolean up;
	
	public HeavyRaider(boolean up) {
		super(defaultLife, defaultSpeed, up? new ImageIcon(urlUp): new ImageIcon(url), defaultWidth, defaultHeight);
		y = -defaultHeight;
		Random rand = new Random();
		x = rand.nextInt(800);
		setFrecuencyShot(7,20);
		this.up = up;
		score = 35;
	}
	
	public synchronized void move() {
		
		if (y < 300) {
			dx = colonial.getX() - x;
			dy = colonial.getY() - y;
			double mod = Math.sqrt(dy*dy+dx*dx);
			setRotacion();
			
			//centra la direccion del Enemigo hacia el jugador
			dx += colonial.getWidth() / 2;
			dy += colonial.getHeight() / 2;
			
			if (dx != 0 || dy != 0) {
				dx = dx / mod;
				dy = dy / mod;
			} else {
				dy = 0.1d;
				dx = 0.1d;
			}
			y += dy * speed;
			x += dx * speed;
		} else {
			y += dy * speed;
			x += dx * speed;
		}
		collisionCheck();
	}
	
	public void shooting() {
		if(cantShot() && y < 350) {
			Shot d = pointAndShoot();
			game.addShotCylon(d);
		}
	}

	public boolean isEspecial() {
		return up;
	}
}
